package com.glance.browser.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import com.glance.browser.domain.User;

@Transactional(readOnly = true)
public interface UserRepository extends JpaRepository<User, String> {
 
	@Query("from User u " + "where u.username=:username")
	public User findByUsername(@Param("username") String username);

	@Query("from User u "
			+ "where u.username=:username and u.password=:password")
	public User findByUsernameAndPassword(@Param("username") String username,
			@Param("password") String password);

	@Modifying
	@Query("delete from User where username != :username")
	public void deleteAllExcept(@Param("username") String username);
	
}

